package net.minecraft.src;
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode 

import java.util.List;
import java.util.Random;
import org.lwjgl.opengl.GL11;

public class EntityTownGuard extends EntityCreature
{

    public EntityTownGuard(World world)
    {
        super(world);
		itemToDrop = 0;
        angerLevel = 0;
        randomSoundDelay = 0;
        texture = "/mob/towngaurd.png";
        moveSpeed = 0.7F;
		health = 40;
        isImmuneToFire = true;
    }

    public void onUpdate()
    {
        moveSpeed = playerToAttack == null ? 0.7F : 1.3F;
        if(randomSoundDelay > 0 && --randomSoundDelay == 0)
        {
        }
        super.onUpdate();
    }

    public void writeEntityToNBT(NBTTagCompound nbttagcompound)
    {
        super.writeEntityToNBT(nbttagcompound);
        nbttagcompound.setShort("Anger", (short)angerLevel);
    }

    public void readEntityFromNBT(NBTTagCompound nbttagcompound)
    {
        super.readEntityFromNBT(nbttagcompound);
        angerLevel = nbttagcompound.getShort("Anger");
    }

    protected Entity findPlayerToAttack()
    {
        if(angerLevel == 0)
        {
            return null;
        } else
        {
            return super.findPlayerToAttack();
        }
    }

    public void onLivingUpdate()
    {
        super.onLivingUpdate();
    }

	public boolean attackEntityFrom(Entity entity, int i)
    {
        if(entity instanceof EntityPlayer)
        {
            List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(32D, 32D, 32D));
            for(int j = 0; j < list.size(); j++)
            {
                Entity entity1 = (Entity)list.get(j);
                if(entity1 instanceof EntityTownGuard)
                {
                    EntityTownGuard entitytownguard = (EntityTownGuard)entity1;
                    entitytownguard.becomeAngryAt(entity);
                }
            }

            becomeAngryAt(entity);
        }
        return super.attackEntityFrom(entity, i);
    }
	
	protected void attackEntity(Entity entity, float f)
    {
        if((double)f < 2.5D && entity.boundingBox.maxY > boundingBox.minY && entity.boundingBox.minY < boundingBox.maxY)
        {
            attackTime = 20;
            entity.attackEntityFrom(this, 4);
        }
    }
	
	public void onDeath(Entity entity)
    {
	itemToDrop = rand.nextInt(6);
	if(itemToDrop == 1)
	{
	dropItem(Item.porkRaw.shiftedIndex,rand.nextInt(3));
	}
	if(itemToDrop == 2)
	{
	dropItem(Item.helmetChain.shiftedIndex,1);
	}
	if(itemToDrop == 3)
	{
	dropItem(Item.plateChain.shiftedIndex,1);
	}
	if(itemToDrop == 4)
	{
	dropItem(Item.legsChain.shiftedIndex,1);
	}
	if(itemToDrop == 5)
	{
	dropItem(Item.bootsChain.shiftedIndex,1);
	}
	if(itemToDrop == 6)
	{
	dropItem(Item.swordSteel.shiftedIndex,1);
	}
	}
	
    public void becomeAngryAt(Entity entity)
    {
        playerToAttack = entity;
        angerLevel = 400 + rand.nextInt(400);
        randomSoundDelay = rand.nextInt(40);
    }

    protected String getHurtSound()
    {
        return "random.hurt";
    }

    protected String getDeathSound()
    {
        return "random.hurt";
    }

    /*protected int getDropItemId()
    {
	return Item.porkRaw.shiftedIndex;
    }*/

    public ItemStack getHeldItem()
    {
        return new ItemStack(Item.swordSteel, 1);
    }
	
	/*public boolean interact(EntityPlayer entityplayer)
	{
	return true;
	}
	*/
	
	public boolean getCanSpawnHere()
    {
        return worldObj.difficultySetting > 0 && worldObj.checkIfAABBIsClear(boundingBox) && worldObj.getCollidingBoundingBoxes(this, boundingBox).size() == 0 && !worldObj.getIsAnyLiquid(boundingBox);
    }

    private int angerLevel;
    private int randomSoundDelay;
	private int itemToDrop;
    private static final ItemStack defaultHeldItem;

    static 
    {
        defaultHeldItem = new ItemStack(Item.swordSteel, 1);
    }
}